<?php
$datas_meta = ($this->view_datas) ?  $this->view_datas->getCurrentItems() : '';
if(!empty($datas_meta[0]['firstName'])) { $this->headMeta()->setName('keywords',$datas_meta[0]['title'].' '.$datas_meta[0]['firstName'].' '.$datas_meta[0]['lastName']);}
if(!empty($datas_meta[0]['firstName'])) { $this->headMeta()->setName('description',$datas_meta[0]['title'].' '.$datas_meta[0]['firstName'].' '.$datas_meta[0]['lastName']); }
if(!empty($datas_meta[0]['firstName'])) { $this->headTitle()->headTitle($datas_meta[0]['title'].' '.$datas_meta[0]['firstName'].' '.$datas_meta[0]['lastName'],'SET')->setSeparator(' - ')->headTitle($this->translator->translator('property_front_page_agent_metatitle')); }

echo $this->headScript()->setFile($this->baseUrl().'/js/jquery/table-sorter/jquery.dataTables.js');
echo $this->headScript()->setFile($this->baseUrl().'/js/jquery/jtruncate/jquery.jtruncate.pack.js');
echo $this->headLink()->setStylesheet($this->baseUrl().'/css/jqueryCSS/table-sorter/pagination_table.css');
$version = Zend_Registry::get('version');
$front_template = Zend_Registry::get('front_template');

$review_helper = new Review_View_Helper_Review();
$maximum_stars_digit = $this->translator->translator('maximum_stars_digit');
// 1ist param options are : like, inline, plus_minus, horizontal, triangle
$vote = new Vote_Controller_Helper_ShowVoteButton('inline','property_page' );

$global_conf = Zend_Registry::get('global_conf');
$currency = new Zend_Currency($global_conf['default_locale']);
	$auth = Zend_Auth::getInstance ();
        $hasIdentity = $auth->hasIdentity ();
        $mem_db = new Members_Model_DbTable_MemberList();
$property_type_arr = explode(',', $this->translator->translator('property_front_page_rent_id'));
function property_truncate($phrase,$start_words, $max_words)
{
   $phrase_array = explode(' ',$phrase);
   if(count($phrase_array) > $max_words && $max_words > 0)
	  $phrase = implode(' ',array_slice($phrase_array, $start_words, $max_words)).'...';  
   return $phrase;
}

?>


<div class="mod">
	<div class="agent-icon">
        <h1><?php echo $this->translator->translator('property_front_page_list').' ('.$this->escape($datas_meta[0]['title'].' '.$datas_meta[0]['firstName'].' '.$datas_meta[0]['lastName']).')'; ?></h1></h1>
    </div>
 
    <div class="social">
         	<!-- AddThis Button BEGIN -->
            <div class="addthis_toolbox addthis_default_style">
            <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
            <a class="addthis_button_tweet"></a>
            <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
            <a class="addthis_counter addthis_pill_style"></a>
            </div>
            <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e89660c7edb029a"></script>
        	<!-- AddThis Button END -->
	</div>

	<div class="clear"></div>
      <?php
     if ($hasIdentity)
      {
       ?> 
	<table id="sortTable" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >
			<tbody>
			  <?php
				foreach($this->view_datas as $entry)
				{
					$property_image_val_arr = explode(',',$entry['property_image']);
					$property_image_no = (empty($property_image_val_arr[0])) ? '0' : count($property_image_val_arr);
					if($this->escape($entry['property_primary_image']))
					{ 
						$thumb_image = 'data/frontImages/property/property_image/'.$this->escape($entry['property_primary_image']); 
					}
					else
					{ 
						if($this->escape($entry['property_image']))
						{
							$thumb_image = 'data/frontImages/property/property_image/'.$this->escape($property_image_val_arr[0]); 
						}
						else
						{
							$thumb_image = 'application/layouts/scripts/'.$front_template['theme_folder'].'/images/mod_property_img/no_image.png'; 
						}		
					}
					if($entry['file_thumb_width'] && ($entry['file_thumb_resize_func'] == 'resizeToWidth' || $entry['file_thumb_resize_func'] == 'resize'))
					{ 
						$width = 'width="'.$this->escape($entry['file_thumb_width']).'"'; 
					}
					else
					{
						$width = '';
					} 
					if($entry['file_thumb_height'] && ($entry['file_thumb_resize_func'] == 'resizeToHeight' || $entry['file_thumb_resize_func'] == 'resize'))
					{ 
						$height = 'height="'.$this->escape($entry['file_thumb_height']).'"'; 
					} 
					else
					{
						$height = '';
					}
						$featured_class = ($entry['featured'] == '1') ? 'products-featured' : '' ;
					?>
					  <tr>
						<td>
                        	<div class="products-list">
                                <!-- list Header Start -->
                                <div class="list-header">
                                	<div class="header-row">
                                    	<div class="header-left">
                                        <span class="title-small"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" class="preview" title="<?php echo $this->escape($entry['property_name']); ?>" link=""><?php echo $this->escape($entry['property_name']); ?></a></span><br />
                                            
                                            <span class="info"><?php if(!empty($entry['feature_room_no'])){ echo (int)$this->escape($entry['feature_room_no']).' '.$this->translator->translator('property_front_page_room'); } ?></span>
                                        </div>
                                    
                                    	<div class="header-middle">
                                            <span class="products-mark"><?php echo $this->translator->translator('property_front_page_property_for'); ?></span>&nbsp;<span class="products-type"><?php echo $this->escape($entry['business_type']); ?></span>
                                        </div>
                                    
                                    	<div class="header-right">                                                
											<?php 
                                                if(!empty($entry['review_id'])){ 
                                                $review_no = $review_helper->getNumOfReviews($entry['id'], $this->escape($entry['review_id']));
                                            ?><span class="products-write-review"><a href="<?php echo $this->url( array('module' => 'Review','controller' => 'frontend', 'action'     => 'write', 'group_id' => $this->escape($entry['review_id']), Eicra_File_Constants::ITEM_ID => $entry['id'] ), 'Review-Write/:group_id/:item_id',    true); ?>"><?php echo $this->translator->translator('common_write_review'); ?></a></span> &nbsp; <span class="products-review-count"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 10 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('common_review_no',htmlentities($review_no)); ?></a></span> <?php } ?>
                                        </div>
                                    </div>
                                </div>
                                <!-- list Header End -->
                                
                                <!-- list Body Start --> 
                                <div class="body-container <?php echo $featured_class; ?>">
                                     <div class="left-content">
                                            
                                            <div class="img-wrapper">
                                            	<a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" class="preview" link="<?php echo $thumb_image; ?>" width="350" title="<?php echo $this->escape($entry['property_name']); ?>"><img src="<?php echo $thumb_image; ?>" <?php echo $width; ?> <?php echo $height; ?> border="0" class="thumb"/></a>
                                                <div class="photo-count-container">
                                                    <div class="photo-count">
                                                        <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 1 ),'Property-details/:property_title/:tab',true); ?>" title="<?php echo $this->translator->translator('property_front_page_click_view_photos'); ?>"><?php echo $this->translator->translator('property_front_page_property_photo_no', $property_image_no); ?></a>
                                                    </div>
                                                </div>                                            
                                            </div>
                                            
                                            <h2>
                                                <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" class="preview" title="<?php echo $this->escape($entry['property_name']); ?>" link=""><?php echo $this->escape(property_truncate($entry['property_name'], 0, 5)); ?></a>
                                            </h2>
                                            
                                            <div class="products-stars">
                                            <?php
                                                for($i = 1; $i < $maximum_stars_digit; $i++)
                                                {
                                                    $property_stars = ($i <= $this->escape($entry['stars'])) ? "<img src='application/layouts/scripts/".$front_template['theme_folder']."/images/mod_property_img/star-active.png' border='0' />" : "<img src='application/layouts/scripts/".$front_template['theme_folder']."/images/mod_property_img/star-inactive.png' border='0'/>";
                                                    echo $property_stars.'&nbsp;';
                                                }
                                            ?>
                                            </div>
                                            
                                            <div class="products-desc">
                                                <p><?php echo $this->translator->translator('property_front_page_property_location'); ?></p> <?php  echo $this->escape($entry['state_name']); ?><br />
                                                <p><?php echo $this->translator->translator('property_front_page_property_country'); ?></p> <?php echo $this->escape($entry['value']); ?><br />
    
                                                <p><?php echo $this->translator->translator('property_front_page_property_desc'); ?></p>
                                                <span class="jTruncate"><?php echo $this->escape(strip_tags($entry['property_desc'])); ?></span>
                                            </div>
                                     </div>
                                     
                                     <div class="right-content">
                                        <span class="products-price">
                                       <span>
                                              <?php  echo $this->translator->translator('property_front_page_price');  ?>
                                            </span>
                                            <span>
                                              <?php

                                             $number = $this->price($this->escape($entry['property_price']));
                                             echo number_format($number, 0, ',', '.');
                       
                                             ?>
                                           </span>
                                       </span>
                                        <ul class="products-options">
                                            <?php
                                            if(!empty($property_type_arr[0]) && in_array($entry['property_type'], $property_type_arr))
                                              {
                                            ?>
                                            
                                            <?php
                                              }
                                              if(!empty($entry['feature_bathroom']))
                                              {
                                            ?>	
                                            <li class="bathroom"><?php  echo $this->translator->translator('maid_age').' '.(int)$this->escape($entry['feature_bathroom']).' '.$this->translator->translator('property_front_page_bathroom'); ?></li>
                                            <?php
                                              }
                                            ?>
                                            
                                            <li class="kitchen"><?php $input = $this->escape($entry['feature_kitchen']); echo str_replace('_', ' ', $input); ?></li>
                                            <li class="garden">
                                              <?php
                                                                            $search  = array('_', 'doctor');
                                                                            $replace = array(' ', 'doctor\'s');
                                                                            $subject = $this->escape($entry['feature_garden']);
                                                                            echo str_replace($search, $replace, $subject);
                                                                          ?>
                                           </li> 

                                            <li class="garage"><?php $input = $this->escape($entry['feature_garage']); echo str_replace('_', ' ', $input); ?></li>
                                        </ul>                              
                                        <div class="products-vote">
                                        	<p><?php echo $this->translator->translator('property_front_page_label_voting'); ?></p>
                                        	<span><?php  $vote->showButton($entry['id'] , $this->escape($entry['property_name'])); ?></span>
                                        </div>
                                     </div>    
                                </div>
                                <!-- list Body End -->
                                
                                 <!-- list footer start -->
                                <div class="list-footer">
                                    <div class="footer-left">
                                        
                                        <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 2 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('property_front_page_property_fpan'); ?></a>  | 
 
                                        <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 1 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('property_front_page_property_photo'); ?></a> | 
                                        <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'emails', 'action' => 'friend','property_title' => $this->escape($entry['property_title']), 'form_id' => $this->translator->translator('email_to_friend_form_id') ),'Email-To-Friend/:property_title/:form_id',true); ?>"><?php echo $this->translator->translator('property_front_page_property_email_friend'); ?></a>
                                    </div>
                                    
                                    <div class="footer-right">
                                    	<span class="products-book-btn"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'emails', 'action' => 'owner','property_title' => $this->escape($entry['property_title']), 'form_id' => $this->translator->translator('contact_owner_form_id') ),'Contact-Owner/:property_title/:form_id',true); ?>"><?php echo $this->translator->translator('property_front_page_property_book'); ?></a></span>
                                        
                                        <span class="products-details-btn"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>"><?php echo $this->translator->translator('property_front_page_property_more'); ?></a></span>
                                    </div>
                                </div>
                                <!-- list footer end -->
                            </div>
                        </td>
					  </tr>
				  <?php
                    }
                  ?>
			</tbody>
		</table>
        <div id="bottomPagination">
            <?php
                echo $this->paginationControl($this->view_datas, 'Sliding', 'frontend/agents-pagination-flickr.phtml'); 	 
            ?>
        </div>
<?php
                    }
                    else
                    {
                ?>


    
    <div class="forbidden-message"><?php echo $this->translator->translator('member_only_view_agency_member'); ?></div>
                              <div class="center">  
                                    <span>
                                      <div class="products-price">
                                        <span class="upper"><a href="Register"><?php echo $this->translator->translator('member_only_register'); ?></a></span>                                                      
                                      </div>
                                    </span>
                                    <span>
                                      <div class="products-price">
                                        <span class="upper"><a href="Frontend-Login"><?php echo $this->translator->translator('login'); ?></a></span>                                                      
                                      </div>
                                    </span>
                                   </div>

 <?php
                    }
                ?>
                   
</div>